package org.yaac.client.activity;

import javax.inject.Inject;

import org.yaac.client.place.YaacPlace;
import org.yaac.client.ui.MenuView;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.activity.shared.Activity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public class MenuActivity extends AbstractActivity {

	private final MenuView view;
	
	/**
	 * @param view
	 */
	@Inject
	MenuActivity(MenuView view) {
		super();
		this.view = view;
	}

	/**
	 * @param place
	 * @return
	 */
	public Activity withPlace(Place place) {
		if (place instanceof YaacPlace) {
			String urlTokenPrefix = ((YaacPlace)place).urlTokenPrefix();
			view.updateCurrPlace(urlTokenPrefix);
		}
		
		return this;
	}

	/* (non-Javadoc)
	 * @see com.google.gwt.activity.shared.Activity#start(com.google.gwt.user.client.ui.AcceptsOneWidget, com.google.gwt.event.shared.EventBus)
	 */
	@Override
	public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {		
		view.setPresenter(this);
		containerWidget.setWidget(view.asWidget());
	}
}